gusucode.com > DLL初学者指南 非MFCC#源码程序 > DLL初学者指南 非MFC/dll_project/DLL_Test_Source/DLL_Test/dll_test.cpp

    // Loading DLLs The Easy Way
#include <iostream>
#include <dll_tutorial.h> // Include our header file, 
						  // I set up my IDE to search the DLL projects directory for this header, if you don't
						  // set it up like that, copy the header file from the DLL project to this projects
						  // Directory and use double quotes(") around the file instead of '<' and '>'

// Must have a main function
int main()
{
	std::cout << Add(23, 43) << std::endl; // call and print the result of Add() from DLL
	Function();     // call Function() from DLL

	std::cin.get(); // Wait for input to prevent opening then closing immediatly

	return(1); // return success
}

/*

LOADING DLLS THE HARDER WAY CODE

I just put this code in as a comment so I wouldn't have to
upload a 3rd file

To use this code simply uncomment this part of the file
and comment out the other code that was originally not
commented out

#include <iostream>
#include <windows.h>
//#include "dll_tutorial.h" // Include our header file, 
						  // I set up my IDE to search the DLL projects directory for this header, if you don't
						  // set it up like that, copy the header file from the DLL project to this projects
						  // Directory and use double quotes(") around the file instead of '<' and '>'

typedef int (*AddFunc)(int,int);
typedef void (*FunctionFunc)();

// Must have a main function
int main()
{
	AddFunc _AddFunc;
	FunctionFunc _FunctionFunc;
	HINSTANCE hInstLibrary = LoadLibrary("DLL_Tutorial.dll");

	if (hInstLibrary == NULL)
	{
		FreeLibrary(hInstLibrary);
	}

	_AddFunc = (AddFunc)GetProcAddress(hInstLibrary, "Add");
	_FunctionFunc = (FunctionFunc)GetProcAddress(hInstLibrary, "Function");

	if ((_AddFunc == NULL) || (_FunctionFunc == NULL))
	{
		FreeLibrary(hInstLibrary);
	}

	std::cout << _AddFunc(23, 43) << std::endl; // call and print the result of Add() from DLL
	_FunctionFunc();     // call Function() from DLL

	std::cin.get(); // Wait for input to prevent opening then closing immediatly

	FreeLibrary(hInstLibrary);

	return(1); // return success
}

*/